<!-- S search -->
<app-search-bar
  [submitLoading]="tableParams.loading"
  [searchOptions]="searchOptions"
  labelFlex="80px"
  (onSearch)="queryData($event)"
  (onReset)="resetData($event)"
>
</app-search-bar>
<!-- E search -->

<nz-card class="m-t-4">
  <div class="oprea-wrap">
    <button
      nz-button
      nzType="primary"
      (click)="jumpPage(0)"
    >新增加价促销</button>
  </div>

  <div class="pagination-wrap-position table-wrap p-t-10">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzOuterBordered
      [nzScroll]="{ x: '1100px' }"
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableParams.loading"
      [nzData]="tableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableParams.total"
      [nzPageIndex]="tableParams.page"
      [nzPageSize]="tableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
    >
      <thead>
        <tr>
          <th nzAlign="center" nzWidth="100px" nzLeft>ID</th>
          <th nzAlign="center" nzWidth="120px">促销状态</th>
          <th nzAlign="center" nzWidth="150px">前端名称</th>
          <th nzAlign="center" nzWidth="200px">备注</th>
          <th nzAlign="center" nzWidth="120px">适用用户</th>
          <th nzAlign="center" nzWidth="120px">适用成色</th>
          <th nzAlign="center" nzWidth="120px">适用机型</th>
          <th nzAlign="center" nzWidth="170px">促销开始时间</th>
          <th nzAlign="center" nzWidth="170px">促销结束时间</th>
          <th nzAlign="center" nzWidth="170px">更新时间</th>
          <th nzAlign="center" nzWidth="250px" nzRight>操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <!-- ID -->
          <td nzAlign="center" nzLeft>{{ data.id }}</td>

          <!-- 促销状态 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.status | makeupDescentListStatus: 'color'}">
              {{ data.status | makeupDescentListStatus: 'label' }}
            </span>
          </td>

          <!-- 前端名称 -->
          <td nzAlign="center">{{ data.showCopy || '-' }}</td>

          <!-- 备注 -->
          <td nzAlign="center">{{ data.name || '-' }}</td>

          <!-- 适用用户 -->
          <td nzAlign="center">
            <div [ngSwitch]="data.userType">
              <div *ngSwitchCase="0">
                <nz-tag>通用</nz-tag>
              </div>
              <div *ngSwitchCase="1">
                <nz-tag [nzColor]="'#87d068'">C端</nz-tag>
              </div>
              <div *ngSwitchCase="2">
                <nz-tag [nzColor]="'#2db7f5'">B端</nz-tag>
              </div>
              <div *ngSwitchDefault>-</div>
            </div>
          </td>

          <!-- 适用成色 -->
          <td nzAlign="center">
            <div [ngSwitch]="data.applyColour">
              <div *ngSwitchCase="0">全部</div>
              <div *ngSwitchCase="1">二手</div>
              <div *ngSwitchCase="2">准新</div>
              <div *ngSwitchDefault>-</div>
            </div>
          </td>

          <!-- 适用机型 -->
          <td nzAlign="center">
            {{ modelToText(data?.containsModel) }}
          </td>

          <!-- 促销开始时间 -->
          <td nzAlign="center">{{ data.beginTime || '-' }}</td>

          <!-- 促销结束时间 -->
          <td nzAlign="center">{{ data.endTime || '-' }}</td>

          <!-- 更新时间 -->
          <td nzAlign="center">{{ data.updateTime || '-' }}</td>
          
          <!-- 操作 -->
          <td nzAlign="center" nzRight>
            <button
              nz-button
              nzSize="small"
              nzType="link"
              (click)="jumpPage(2, data)"
            >查看</button>

            <button
              nz-button
              nzSize="small"
              nzType="link"
              (click)="jumpPage(1, data)"
            >编辑</button>

            <button
              nz-button
              nzSize="small"
              nzType="link"
              (click)="jumpPage(3, data)"
            >复制</button>

            <a
              *ngIf="[1, 2].includes(data.status)"
              nz-button
              nzSize="small"
              nzType="link"
              nzDanger
              nz-popconfirm
              nzPopconfirmTitle="确认停止该活动？停止后不可重新启动"
              (nzOnConfirm)="stopDelActivity(data, 4)"
            >停止</a>

            <a
              *ngIf="[5].includes(data.status)"
              nz-button
              nzSize="small"
              nzType="link"
              nzDanger
              nz-popconfirm
              nzPopconfirmTitle="确认删除？不可以反悔的哦"
              (nzOnConfirm)="stopDelActivity(data, 8)"
            >删除</a>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>